<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 门店收银台开关编码分组属性模型
 *
 * @property int $id 主键ID
 * @property int $in_type 置换类型
 * @property string $in_type_name 置换类型名称
 * @property int $state 状态
 */
class StoreCashierSwitchCodeGroupProperties extends Model
{
    protected $table = 'ims_yz_store_cashier_switch_code_group_properties';
    
    protected $fillable = [
        'pid',
        'in_type',
        'in_type_name',
        'in_type_attribute',
        'out_type',
        'out_type_attribute',
        'uniacid',
        'created_at',
        'updated_at',
        'settlement_num',
        'state'
    ];

    protected $hidden = [];
    
    protected $casts = [
        'id' => 'integer',
        'in_type' => 'integer',
        'state' => 'integer'
    ];

    /**
     * 查询启用的属性
     */
    public function scopeEnabled($query)
    {
        return $query->where('state', 1);
    }

    /**
     * 获取所属分组
     */
    public function group()
    {
        return $this->belongsTo(StoreCashierSwitchCodeGroup::class, 'pid');
    }
    
    /**
     * 关联门店关系
     */
    public function storeRelations()
    {
        return $this->hasMany(StoreCashierSwitchCodeGroupRelation::class, 'group_propertie_id', 'id');
    }
}
